﻿Option Infer On
Imports Core
Imports System
Imports System.Diagnostics
Imports System.IO
Imports System.Net
Imports System.Windows
Imports System.Windows.Controls
Imports System.Windows.Data
Imports System.Windows.Media
Imports System.Windows.Media.Animation
Imports System.Windows.Navigation
Imports Feed
Partial Public Class Main
    Delegate Sub PlayAnimation()
    Dim aniThread As System.Threading.Thread
    Dim subsman As Feed.Database.SubscriptionManager
    Public dlfeed As Feed.Base.FeedBase = New Feed.Base.FeedBase
    Public Sub New()
        MyBase.New()
        Me.InitializeComponent()
    End Sub
    Private Sub CTabButton_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs)

    End Sub
    Private Sub Update_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Update.Click
        Try
            working.Visibility = Windows.Visibility.Visible
            working.StatusText = "Updating Feeds....."
            working.StartAnimation()
            subsman.StartRefreshAllFeeds()
            'Dim B = Feed.Rendering.FeedItems.RenderSingleItem([Global].Items(0), "Bluepearl")
            'CType(bcontainer.Content, FeedViewPage).BrowserDocumentText = B
            'Diagnostics.Debug.Print([Global].Items.Count)
        Catch ex As Exception
            Debug.Print(ex.ToString)
        End Try
    End Sub
    Private Sub HideWorkAni()
        working.Visibility = Windows.Visibility.Hidden
    End Sub
    Private Sub PlayWorkAni()
        working.StartAnimation()
    End Sub
    Private Sub PlayWorking()
        Me.Dispatcher.BeginInvoke(Windows.Threading.DispatcherPriority.Normal, New PlayAnimation(AddressOf PlayWorkAni))
    End Sub
    Private Sub UpdateComplete()
        working.StopMe()
        Me.Dispatcher.BeginInvoke(Windows.Threading.DispatcherPriority.Normal, New PlayAnimation(AddressOf HideWorkAni)) 'Function() working.Visibility = Windows.Visibility.Hidden))
    End Sub
    Private Sub Main_ContentRendered(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ContentRendered
        aniThread = New System.Threading.Thread(AddressOf PlayWorking)
        subsman = New Feed.Database.SubscriptionManager(API.ReturnDataPath & "subscriptions.xml")
        AddHandler subsman.RefreshAllFeedsComplete, AddressOf UpdateComplete
        Dim x = Rendering.MakeSubscriptionList.ReturnList(True)
        CType(bcontainer.Content, FeedViewPage).BrowserDocumentText = x
    End Sub
    Private Sub Window1_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Try
            CType(Me.bcontainer.Content, FeedViewPage).Width = bcontainer.Width
            CType(Me.bcontainer.Content, FeedViewPage).Height = bcontainer.Height
        Catch ex As Exception
            Debug.Print(ex.ToString)
        End Try
    End Sub
End Class
